namespace Vanilla.UI

class ZoomGadget (Frame):
	_x_scale as double = 1.0
	XScale as double:
		get:
			return Size.Width / Child.Size.Width if Child != null and AutoScale
			return _x_scale
		set:
			return if _x_scale == value
			_x_scale = value
			Pack()

	
	_y_scale as double = 1.0
	YScale as double:
		get:
			return Size.Height / Child.Size.Height if Child != null and AutoScale
			return _y_scale
		set:
			return if _y_scale == value
			_y_scale = value
			Pack()

	Scale as double:
		set:
			XScale = value
			YScale = value
	
	AutoScale as bool

	def constructor (p as Box, s as double):
		super(p)
		DrawFrame = false
		Scale = s
	
	def constructor (p as Box):
		super(p)
		DrawFrame = false
		AutoScale = true
	
	def Draw (b as Brush):
		b.Scale(XScale, YScale)
		super(b)
	
	override def ContainsMouseAt (x as double, y as double):
		return super(x/XScale, y/YScale)
	
	override def MouseDown (b as MouseButton, x as double, y as double):
		super(b, x/XScale, y/YScale)
	
	override def MouseUp (b as MouseButton, x as double, y as double):
		super(b, x/XScale, y/YScale)
	
	override def MouseMotion (x as double, y as double):
		super(x/XScale, y/YScale)
	
	override def RedrawArea(r as Rect):
		print "zoom - RedrawArea(${r})"
		super(Rect(r.X*XScale, r.Y*YScale, r.X2*XScale, r.Y2*YScale))
	
	override def Arrange ():
		if AutoScale:
			Child.Position = Position(0,0)
			Child.Size = Child.MinSize
		else:
			Child.Position = Position(0,0)
			Child.Size = Size(Size.Width / XScale, Size.Height / YScale)
